//package com.sentinel.utils;
//
//import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.BlockRequestHandler;
//import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.GatewayCallbackManager;
//import com.alibaba.csp.sentinel.datasource.Converter;
//import com.alibaba.csp.sentinel.datasource.ReadableDataSource;
//import com.alibaba.csp.sentinel.datasource.nacos.NacosDataSource;
//import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
//import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
//import com.alibaba.csp.sentinel.slots.system.SystemRule;
//import com.alibaba.csp.sentinel.slots.system.SystemRuleManager;
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.TypeReference;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.MediaType;
//import org.springframework.web.reactive.function.BodyInserters;
//import org.springframework.web.reactive.function.server.ServerResponse;
//
//import javax.annotation.PostConstruct;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
///**
// * Copyright
// *
// * @Author WuHuang
// * @Date 2022/5/31
// */
//@Configuration
//public class GatewayConfig {
//    /**
//     * 自定义限流处理器
//     */
//@PostConstruct
//public void initBlockHandlers() {
//        BlockRequestHandler blockHandler = (serverWebExchange, throwable) -> {
//        HashMap<String,String> map = new HashMap();
//        map.put("code",HttpStatus.TOO_MANY_REQUESTS.toString());
//        map.put("message","限流了");
//        return ServerResponse.status(HttpStatus.OK)
//        .contentType(MediaType.APPLICATION_JSON_UTF8)
//        .body(BodyInserters.fromObject(map));
//        };
//        GatewayCallbackManager.setBlockHandler(blockHandler);
//        }
//
////    @PostConstruct
//    private void init() throws Exception{
//        String remoteAddress = "127.0.0.1:8848";
//        String groupId = "SENTINEL_GROUP";
//        String dataId  = "demo-gateway-system-rules";
//
//        Converter<String, List<SystemRule>> parser = source -> JSON.parseObject(source, new TypeReference<List<SystemRule>>() {});
//        ReadableDataSource<String, List<SystemRule>> nacosDataSource = new NacosDataSource<>(remoteAddress, groupId, dataId, parser);
//        SystemRuleManager.register2Property(nacosDataSource.getProperty());
//    }
//}
//
